const  PropertyValidate = {
  "TimeLine": {
    "起点": [
      { 
        "lessThen": '终点',
        "errorMsg": '起点必须小于终点!'
      }
    ],
    "终点": [
      { 
        "moreThen": '起点',
        "errorMsg": '终点必须大于起点!'
      }
    ],
    "步长": [
      { 
        "min": 0,
        "errorMsg": '步长必须大于0!'
      }
    ]
  },
  "CommandAction": {
    "发生时间点": [
      { 
        "moreThen:parent": "起点",
        "errorMsg": '发生时间点必须大于起点!'
      },
      { 
        "lessThen:parent": '终点',
        "errorMsg": '发生时间点必须小于终点!'
      }
    ]
  }
};

export  function validate(GraphNode, value, property){
  let result = true; 
  let errorMsg = [];
  const typeName = GraphNode.getTypeName();
  if (Reflect.has(PropertyValidate, typeName)){
    const rules = PropertyValidate[typeName][property.config.name];
    if (Array.isArray(rules) && rules.length > 0){
      
      result =  rules.every(rule => {
        const key = Object.keys(rule)[0];
        const target = Object.values(rule)[0];
		  if (key === 'lessThen'){
          if (! (value <=	GraphNode.getPropertyByPropertyName(target)?.getValue()) ) {
            errorMsg.push(rule.errorMsg);
            return false;
          }
           
		  }
        if (key === 'moreThen'){
          if (! (value >=	GraphNode.getPropertyByPropertyName(target)?.getValue()) ) {
            errorMsg.push(rule.errorMsg);
            return false;
          }
		  }
        if (key === 'max'){
          if (!( value <= target )){
            errorMsg.push(rule.errorMsg);
            return false;
          }
           
		  }
        if (key === 'min'){
          if (! (value >= target)){
            errorMsg.push(rule.errorMsg);
            return false;
          }
           
		  }
        if (key === 'moreThen:parent'){
          if ( !(value >=	GraphNode.container.getPropertyByPropertyName(target)?.getValue())){ 
            errorMsg.push(rule.errorMsg);
            return false;
          }
           
        }
        if (key === 'lessThen:parent'){
          if (!( value <= GraphNode.container.getPropertyByPropertyName(target)?.getValue() )){
            errorMsg.push(rule.errorMsg);
            return false;
          }
           
        }
        return true;
      });
    }
  }
  errorMsg = errorMsg.join(',');
  return result || errorMsg;
}